<?php
/**
 * ELikeFoto
 * @package Entity
 */
/**
 * 
 * Enter description here ...
 * @package Entity
 *
 */
class ELikeFoto extends EEntity implements JSONSerializable{
	/**
	 * 
	 * Id della foto
	 * @var int
	 */
	private $fotoid;
	/**
	 * 
	 * username del votante
	 * @var string
	 */
	private $writer;
	/**
	 * 
	 * Mi piace
	 * @var string
	 */
	private $like;
	/**
	 * Costruttore
	 */
	public function __construct(){
		 parent::__construct();
	}
	/**
	 * getFotoId
	 * @return int
	 *
	 */
	public function getFotoId(){
		return $this->fotoid;
	}
	/**
	 * getWriter
	 * @return string
	 */
	public function getWriter(){
		return $this->writer;
	}
	/**
	*
	* getLike
	* @return string
	*/
	public function getLike(){
		return $this->like;
	}	

	/**
	 * 
	 * setIdFoto
	 * @param integer $id
	 */
	public function setIdFoto($idfoto) {
		if(empty($idfoto)){
			throw new ExceptionDati('Campo Id lasciato vuoto!');
		}
		$this->fotoid = $idfoto;
	}
	/**
	 * 
	 * setWriter
	 * @param string $votante
	 */
	public function setWriter($writer) {
		if(!preg_match(RX_USERNAME,$writer)){
			throw new ExceptionDati('Campo Votante errato!');
		}
		$this->writer = $writer;
	}
	
	/**
	 * 
	 * setLike
	 * @param integer $like
	 */
	public function setLike($like) {
		if($like==1){
			$this->like = $like;
		}
		
	}
	
	
	/**
     * jsonEncode
     * @return string
     */
    public function jsonEncode() {
    	$result = '{';
    	
    	$i = 0;
    	foreach($this as $key => $value) {
    			
    		if($i != 0){
    			$result .= ',';
    		}
    			
    		$result .= JSON_encode($key).':'.JSON_encode($value);
    		$i++;
    	}
    	
    	$result .= '}';
    	
    	return $result;
    }
    /**
     * jsonDecode
     * @param stdClass $json
     */
    public function jsonDecode($json) {
    	foreach($json as $key => $value){
    		$this->{'set'.$key}($value);
    	}
    }
    /**
     * toArray
     * @return array
     */
    public function toArray() {
    	$result = array();
    	foreach($this as $key => $value) {
    		$result[$key] = $value;
    	}
    	return $result;
    }
	
	
}

